﻿using Microsoft.Xna.Framework.Input;

namespace Origin2.Framework
{
    // NOTE: CALL UPDATE!
    // TODO: ADD HELPER METHODS!
    /// <summary>
    /// Manages input, and also holds previous and current keyboard and mouse states
    /// </summary>
    /// <remarks> If you are using this with a custom implementation of the framework, DON'T FORGET TO CALL UPDATE! </remarks>
    public static class InputManager
    {
        /// <summary>
        /// The current keyboard state
        /// </summary>
        public static KeyboardState CurrentKeyboardState { get; private set; }

        /// <summary>
        /// The previous keyboard state (from the last update cycle)
        /// </summary>
        public static KeyboardState PreviousKeyboardState { get; private set; }

        /// <summary>
        /// The current mouse state
        /// </summary>
        public static MouseState CurrentMouseState { get; private set; }

        /// <summary>
        /// The previous mouse state (from the last update cycle)
        /// </summary>
        public static MouseState PreviousMouseState { get; private set; }

        /// <summary>
        /// Updates the input states
        /// </summary>
        public static void Update()
        {
            Flush();

            CurrentKeyboardState = Keyboard.GetState();
            CurrentMouseState = Mouse.GetState();
        }

        /// <summary>
        /// Sets the previous keyboard state to the current one (to prevent washover between states, for example)
        /// </summary>
        public static void FlushKeyboard()
        {
            PreviousKeyboardState = CurrentKeyboardState;
        }

        /// <summary>
        /// Sets the previous mouse state to the current one (to prevent washover between states, for example)
        /// </summary>
        public static void FlushMouse()
        {
            PreviousMouseState = CurrentMouseState;
        }

        /// <summary>
        /// Flushes the keyboard and mouse states
        /// </summary>
        public static void Flush()
        {
            FlushKeyboard();
            FlushMouse();
        }
    }
}
